package com.project.dao.impl;

import com.project.bean.StudentBean;
import com.project.dao.IstudentDao;

import java.time.LocalDate;
import java.util.List;

/**
 * @Title: StudengDaoImpl
 * @Package: com.project.dao.impl
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/7/12 - 13:56
 */
@SuppressWarnings("all")
public class StudengDaoImpl extends BaseDao implements IstudentDao {
    @Override
    public void add(StudentBean studentBean) {
        updateData("INSERT INTO t_student(studentName,phone,birthday,grade VALUES(?,?,?,? ))",studentBean.getStudentName(),studentBean.getPhone(),studentBean.getBirthday(),studentBean.getGrade());
    }

    @Override
    public void del(Integer id) {
        updateData("delete from t_student where id=?",id);
    }

    @Override
    public void update(Integer id, String phone) {
        updateData("UPDATE t_student SET phone=? WHERE id=?",phone,id);
    }

    @Override
    public StudentBean findById(Integer id) {
        return (StudentBean) find("SELECT * FROM t_student WHERE id=?",StudentBean.class,id);
    }

    @Override
    public List<StudentBean> findAll() {
        return this.find("SELECT *FROM t_student",StudentBean.class);
    }

    @Override
    public List<StudentBean> finfByItem(String name, LocalDate startDate, LocalDate endDate) {
        return find("SELECT * FROM t_student WHERE studentName LIKE ? AND birthday>=? AND birthday<=?;",StudentBean.class,name,startDate,endDate);
    }
}
